package com.zeny.edu.common;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName ResponseResult
 * @Description TODO
 * @Author zeny
 * @Date 2020/2/24 15:03
 * @Version 1.0
 */
@Data
public class ResponseResult{
    private Boolean success;
    private Integer code;
    private String message;
    private Map<String, Object> data = new HashMap<>();

    public ResponseResult() {
    }
    public ResponseResult(ResultCode resultCode) {
        this.success = resultCode.getSuccess();
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
    }

    public static ResponseResult ok() {
        ResponseResult responseResult = new ResponseResult(ResultCode.SUCCESS);
        return responseResult;
    }

    public static ResponseResult fail() {
        ResponseResult responseResult = new ResponseResult(ResultCode.ERROR);
        return responseResult;
    }

    public static ResponseResult auth() {
        ResponseResult responseResult = new ResponseResult(ResultCode.AUTH);
        return responseResult;
    }
    public static ResponseResult exception() {
        ResponseResult responseResult = new ResponseResult(ResultCode.EXCEPTION);
        return responseResult;
    }

    public ResponseResult data(Map<String, Object> data) {
        this.data = data;
        return this;
    }
    public ResponseResult data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }
    public ResponseResult message(String message) {
        this.message = message;
        return this;
    }

    public ResponseResult code(Integer code) {
        this.code = code;
        return this;
    }
}
